﻿using System;
using fastCSharp;

namespace diantou.web.contest
{
    /// <summary>
    /// 比赛主页动态
    /// </summary>
    [fastCSharp.code.cSharp.webView(IsPool = true, IsReferer = false)]
    partial class index : view<index>
    {
        /// <summary>
        /// 比赛动态缓存数据
        /// </summary>
        private struct cacheValue
        {
            /// <summary>
            /// 最后一个提交完成时间
            /// </summary>
            public long Ticks;
            /// <summary>
            /// 提交记录
            /// </summary>
            public diantou.dataAccess.contestJudge.finishedJudge[] Judges;
            /// <summary>
            /// 总数量
            /// </summary>
            public int Count;
            /// <summary>
            /// 
            /// </summary>
            /// <param name="page"></param>
            public void Set(index page)
            {
                page.judges = Judges;
                page.judgeTicks = Ticks;
                page.pageInfo.Set(50, Count);
            }
        }
        /// <summary>
        /// 比赛主页动态客户端缓存
        /// </summary>
        private static readonly fastCSharp.sql.logCache<int, cacheValue>.array cache = new fastCSharp.sql.logCache<int, cacheValue>.array(diantou.dataAccess.tcpCall.contestJudge.onFinishedJudgeLog, 4);
        /// <summary>
        /// 提交记录
        /// </summary>
        [fastCSharp.emit.webView.clearMember]
        private diantou.dataAccess.contestJudge.finishedJudge[] judges;
        /// <summary>
        /// 最后一个提交完成时间
        /// </summary>
        private long judgeTicks;
        /// <summary>
        /// 比赛主页动态
        /// </summary>
        /// <param name="contestId">比赛标识</param>
        /// <param name="page">分页号</param>
        /// <returns>是否成功</returns>
        private bool loadView(int contestId, string randomCode, int page)
        {
            if (base.loadView(contestId, randomCode))
            {
                fastCSharp.sql.logCache<int, cacheValue>.array.value cacheValue = page <= 1 ? cache.Get(contestId) : default(fastCSharp.sql.logCache<int, cacheValue>.array.value);
                if (cacheValue.Value.Judges == null)
                {
                    cacheValue.Value.Judges = diantou.dataAccess.tcpCall.contestJudge.getFinishedJudges(contestId, 50, page, out cacheValue.Value.Count, out cacheValue.Value.Ticks);
                    cache.Set(ref cacheValue);
                }
                pageInfo.Page = page;
                cacheValue.Value.Set(this);
                if (requestHeader.IsSearchEngine) pageInfo.Path = contest.Path.Index.ToPageString();
                return true;
            }
            return false;
        }
    }
}
